package com.quzi.kettle.view;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;

import com.quzi.kettle.R;


public class TwoChoseButton extends FrameLayout{

	private Button leftBtn, rightBtn;
	private int status = LEFTBUTTON;
	public final static int RIGHTBUTTON = 1;
	public final static int LEFTBUTTON = 2;
	public final static int CENTERBUTTON = 3;
	private ITwoChoseButton mlistener;
	
	public void setOnChooseListener(ITwoChoseButton listener){
		this.mlistener = listener;
	}
	
	public TwoChoseButton(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context, attrs, defStyle);
	}

	public TwoChoseButton(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context, attrs, 0);
	}

	public TwoChoseButton(Context context) {
		super(context);
		init(context, null, 0);
	}

	
	private void init(Context context, AttributeSet attrs, int defStyleAttr) {
		View.inflate(context, R.layout.view_chose_button, this);

		this.leftBtn = (Button) findViewById(R.id.leftbtn);
		this.rightBtn = (Button) findViewById(R.id.rightbtn);
	
		this.leftBtn.setTag(0);
		this.rightBtn.setTag(2);
	}

	public void setRightButtonText(int str){
		this.rightBtn.setText(str);
	}
	
	public void setRightButtonText(String str){
		this.rightBtn.setText(str);
	}
	
	public void setLeftButtonText(int str){
		this.leftBtn.setText(str);
	}
	
	public void setLeftButtonText(String str){
		this.leftBtn.setText(str);
	}
	
	/**
	 * get Current Clicked info
	 * @return
	 */
	public int getStatus(){
		return this.status;
	}
	
	public void clickRightBtn(){
		this.status = RIGHTBUTTON;
		this.leftBtn.setTextColor(getResources().getColor(R.color.pink));
		this.leftBtn.setBackground(getResources().getDrawable(android.R.color.transparent));
		this.rightBtn.setTextColor(getResources().getColor(R.color.white));
		this.rightBtn.setBackground(getResources().getDrawable(R.drawable.shape_background_right_down));
	}
	
	public void clickCenterBtn(){
		this.status = CENTERBUTTON;
		this.leftBtn.setTextColor(getResources().getColor(R.color.pink));
		this.leftBtn.setBackground(getResources().getDrawable(android.R.color.transparent));
		this.rightBtn.setTextColor(getResources().getColor(R.color.pink));
		this.rightBtn.setBackground(getResources().getDrawable(android.R.color.transparent));
	}
	
	public void clickLeftBtn(){
		this.status = LEFTBUTTON;
		this.leftBtn.setTextColor(getResources().getColor(R.color.white));
		this.leftBtn.setBackground(getResources().getDrawable(R.drawable.shape_background_left_down));
		this.rightBtn.setTextColor(getResources().getColor(R.color.pink));
		this.rightBtn.setBackground(getResources().getDrawable(android.R.color.transparent));
	}
	
	public void setOnRightButtonClickListener(MClickListener listener) {
		if(this.mlistener != null){
			this.mlistener.ClickRight();
		}
		this.rightBtn.setOnClickListener(listener);
	}
	
	public void setOnLeftButtonClickListener(MClickListener listener){
		this.leftBtn.setOnClickListener(listener);
	}
	
	public class MClickListener implements View.OnClickListener{

		@Override
		public void onClick(View view) {
			// TODO Auto-generated method stub
			switch((Integer)view.getTag()){
				case 0:
					clickLeftBtn();
					if(mlistener != null){
						mlistener.ClickLeft();
					}
					break;
				case 1:
					clickCenterBtn();
					break;
				case 2:
					clickRightBtn();
					if(mlistener != null){
						mlistener.ClickRight();
					}
					break;
				}
		}
		
	}
	
	
}
